<?
/**
 * VoiceOne Settings/User/
 *
 * Frontend to provide access to the user system in voiceone.
 * @package voiceone
 * @subpackage  settings_user
 */
  include ("../../admin/config/cfg.php");
  global $cwlang, $cwLanguage;

  //================== GET ===================
  $alert=getAlert();
  // del user
  if ($_GET["cmd"]=="del") {
    $ret=$asterisk->delUser($_GET["id"]);
    if ($ret==1) $alert="<div class=\"AlertGood\">".T_("The user has been deleted")."</div>";
    else $alert="<div class=\"AlertBad\">".T_("The user hasn't been deleted")."</div>";
    goToMainPage($alert,"./");
  }
	//================ PAGE LOGIC ================
  $ret=$asterisk->getUser(0);
  if ($err=$asterisk->getError()) die("Error: $err");
  $count_super=0;
	$count_conf=0;
	$count_standard=0;
	$html_super="";
	$html_conf="";
	$html_standard="";
  if (is_array($ret)) {
    foreach($ret as $v) {
      $id=$v["id"];
      $name=$v["username"];
      $type=$v["type"];
      $entity_id=$v["entity_id"];

      if ($entity_id>0) $lock="<img src=\"$relBasePath/public/img/lock.gif\" alt=\"Locked\" />"; else $lock="";
      if ($entity_id==0) $del="<a href=\"$PHP_SELF?cmd=del&id=$id\" onclick=\"if (confirm('Are you sure to remove $name?')) return true; else return false;\"><img src=\"$relBasePath/public/img/trash.gif\" /></a>"; else $del="";
			if ($type==USER_SUPERUSER){
				 $icon="<img src=\"$relBasePath/public/img/user_superuser.gif\" alt=\"Super User\" />";
				 if($html_super=="") $html_super="</tr><tr><td colspan=\"2\" class=\"todolisttitle\">".T_("SuperUser")."</td></tr><tr>\n";
				 if ($cwUserInfo["type"]==USER_CONFIGURATOR) $html_super.="<td> $icon $name $lock</td>\n";
				 else $html_super.="<td> $icon <a href=\"edit/?id=$id\">$name</a> $lock $del</td>\n";
 				 if ((++$count_super)%2==0) $html_super.="</tr><tr>\n";
			}else if ($type==USER_CONFIGURATOR){
			   $icon="<img src=\"$relBasePath/public/img/user_configurator.gif\" alt=\"Configurator User\" />";
				 if($html_conf=="") $html_conf="</tr><tr><td colspan=\"2\" class=\"todolisttitle\">".T_("Configurator")."</td></tr><tr>\n";
				 $html_conf.="<td> $icon <a href=\"edit/?id=$id\">$name</a> $lock $del</td>\n";
				 if ((++$count_conf)%2==0) $html_conf.="</tr><tr>\n";
			}else if ($type==USER_STANDARD){
      	 $icon="<img src=\"$relBasePath/public/img/user_standard.gif\" alt=\"Standard User\" />";
				 if($html_standard=="") $html_standard="</tr><tr><td colspan=\"2\" class=\"todolisttitle\">".T_("Standard User")."</td></tr><tr>\n";
				 $html_standard.="<td> $icon <a href=\"edit/?id=$id\">$name</a> $lock $del</td>\n";
				 if ((++$count_standard)%2==0) $html_standard.="</tr><tr>\n";
			}
    }
  }
  $html=$html_super.$html_conf.$html_standard;

  //================ MAIN CONTENTS ================
  ob_start();
  ?>
  <div class="SectionHeader">
    <?=$alert?>
    <h1><?=T_("Users")?></h1>
    <h3>
      <a href="edit/" class="admin" ><?=T_("New user")?></a>
    </h3>
  </div>
  <table class="todolist">
    <tr>
      <?=$html?>
    </tr>
  </table>
  <?
  $contents=ob_get_contents();
  ob_end_clean();

  //================ SIDEBAR ================
  ob_start();
  ?>
        <div class="Sidebar">
          <h1><?=T_("The users")?></h1>
          <p><?=T_("From this page, we can manage the VoiceOne access. We can create, modify and delete users.")?></p>
          <p><?=T_("There are three kind of users:")?>
          <ul>
            <li>
             <img src="<?=$relBasePath?>/public/img/user_standard.gif" alt="<?=T_("Standard User")?>" align="left"/><?=T_("The <strong>Standard User</strong>, that can access to the user panel only (Personal VoiceOne)")?>
            </li>
            <li>
             <img src="<?=$relBasePath?>/public/img/user_configurator.gif" alt="<?=T_("Configurator User")?>" align="left"/><?=T_("The <strong>Configurator</strong>, that can access to some section of the VoiceOne Configurator")?>
            </li>
            <li><img src="<?=$relBasePath?>/public/img/user_superuser.gif" alt="<?=T_("Super User")?>" align="left"/><?=T_("The <strong>Super User</strong>, that can do everything inside the VoiceOne Configurator")?>
            </li>
          </ul></p>
          <p><?=T_("Every extensions have an standard user account inside VoiceOne. It is possible however create VoiceOne users not related to extensions. In both the cases, the superuser can change the user type (standard, configurator, superuser).")?></p>
        </div>
  <?
  $sidebar=ob_get_contents();
  ob_end_clean();

  //================ SETTINGS ================

  $smarty->assign("section", "user");
  $smarty->assign("subsection", "");
  $smarty->assign("templateType", "TwoColLeft");  //OneCol, TwoColLeft, TwoColRight
  $smarty->assign("contents", $contents);
  $smarty->assign("sidebar", $sidebar);
  $smarty->display('settings.tpl');
?>

